import { TextModel, SelectionModel } from "../models";
import { SourceView } from "./source_view";
import md2html from '../mdParse'
/**视图渲染 */
export class SourceAndPreview extends SourceView{
    private previewElement_; // 双屏右侧的显示元素
    constructor (textModel: TextModel, selectionModel: SelectionModel, viewContainer: HTMLElement) {
        super(textModel, selectionModel, viewContainer)  
        let viewContainerEle: HTMLElement = this.getViewContainer().parentElement || document.body
        const previewElement = document.createElement('pre')
        previewElement.setAttribute('class', 'container-pre preview')
        previewElement.setAttribute('id', 'source-preview')
        viewContainerEle.appendChild(previewElement)
        this.previewElement_ = previewElement
    }
    render () {
        this.getViewContainer().innerHTML = this.getTextModel().getSpacers() + '\n'
        /**出现首位置光标渲染问题 */
        Promise.resolve().then(() => {
            /**更新偏移量 */
            this.updateDomSelection()
        })
        // this.previewElement_.innerHTML = md2html(this.getTextModel().getSpacers(),'**','<b>','</b>')
        this.previewElement_.innerHTML = md2html(this.getTextModel().getSpacers(),'*','<i>','</i>')
        // this.previewElement_.innerHTML = md2html(this.getTextModel().getSpacers(),'~','<u>','</u>')
    }
}
